<?
    include './common.php';
    $title = $_POST['title'];
    $content = $_POST['content'];
    $type = $_POST['type'];
    $country = $_POST['country'];

    if(!file_exists("uploads")){     //看是否存在文件夹uploads
        mkdir("uploads");
    }
    
    $now =Time();

    // echo $now; 

    $path = $_FILES['img']['tmp_name'];
    move_uploaded_file($path,"uploads/".$_FILES['img']['name']);
    $imgSrc = $_FILES['img']['name'];
    $sql = "INSERT INTO `news`(header,contents,typeid,countryid,imgSrc,ptime) VALUES ('{$title}','{$content}',{$type},{$country},'{$imgSrc}',$now)";
    // echo $sql ; 
    $arr = [] ;
    $res = mysqli_query($link,$sql);
    if( $res ){
        $arr['status'] = 1;
        $arr['info'] = "添加成功";
        $arr['img'] = $imgSrc ; 
    } else{
        $arr['status'] = 0;
        $arr['info'] = "添加失败";
    }
    echo json_encode($arr);
?>